package com.ruoyi.eqmonitor.smdtv.service.impl;

import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.eqmonitor.dtos.CockpitRiverwayAlarmDto;
import com.ruoyi.eqmonitor.vo.CockpitVo;
import com.ruoyi.eqmonitor.dtos.OptDeviceAlarmDto;
import com.ruoyi.eqmonitor.service.IOptPatrolEventService;
import com.ruoyi.eqmonitor.smdtv.domain.SmdtvOutletProblem;
import com.ruoyi.eqmonitor.smdtv.mapper.SmdtvOutletProblemMapper;
import com.ruoyi.eqmonitor.smdtv.service.ISmdtvOutletProblemService;
import com.ruoyi.eqmonitor.utils.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-03-12
 */
@Service
public class SmdtvOutletProblemServiceImpl extends ServiceImpl<SmdtvOutletProblemMapper, SmdtvOutletProblem> implements ISmdtvOutletProblemService {
    
    @Autowired
    private SmdtvOutletProblemMapper smdtvOutletProblemMapper;

    @Autowired
    private IOptPatrolEventService optPatrolEventService;

    @Override
    public SmdtvOutletProblem selectSmdtvOutletProblemById(Long id){
        return smdtvOutletProblemMapper.selectSmdtvOutletProblemById(id);
    }
      
    @Override
    public List<SmdtvOutletProblem> selectSmdtvOutletProblemList(SmdtvOutletProblem smdtvOutletProblem){
        return smdtvOutletProblemMapper.selectSmdtvOutletProblemList(smdtvOutletProblem);
    }

    @Override
    public List<OptDeviceAlarmDto> cockpitRiverwayAlarm(CockpitRiverwayAlarmDto dto) {
        List<OptDeviceAlarmDto> list = new ArrayList<>();
        if (dto.getAlarmCode() != 1){
            List<CockpitVo> vos = smdtvOutletProblemMapper.cockpitRiverwayAlarm(dto);
            list = optPatrolEventService.reCockpitData(vos, "排口");
        }
        return list;
    }

    @Override
    public boolean updateConfirmAlarmToInDisposal(String alarmId,Integer state) {
        if (ObjectUtil.isNull(alarmId)) return false;
        LambdaUpdateWrapper<SmdtvOutletProblem> wrapper = Wrappers.lambdaUpdate();
        if (state == 1){
            wrapper.set(SmdtvOutletProblem::getConfirmAlarm, Constant.ConfirmAlarmType.IN_DISPOSAL.getValue());
        }else {
            wrapper.set(SmdtvOutletProblem::getConfirmAlarm, Constant.ConfirmAlarmType.CLEARED.getValue());
        }
        wrapper.eq(SmdtvOutletProblem::getId, alarmId);
        return update(wrapper);
    }
}